<template>
    <el-dialog title="参数" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true"
        class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px">
        <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right"
            :disabled="readOnly">
            <el-form-item label="破坏性数量" prop="DestructivenessQty">
                <el-input v-model='dataForm.DestructivenessQty' placeholder='请输入破坏性数量' clearable required
                    :style='{ "width": "100%" }' maxlength='200'>
                </el-input>
            </el-form-item>
            <el-form-item v-for="(item, index) in parameter" :label="item.label" :prop="item.key" :key="index">
                <el-input v-model='item.value' :placeholder="'请输入' + item.label" clearable required
                    :style='{ "width": "100%" }' maxlength='200'>
                </el-input>
            </el-form-item>
            <el-form-item label="备注" prop="Remarks">
                <el-input v-model="dataForm.Remarks" show-word-limit :style='{ "width": "100%" }' type='textarea'
                    :autosize='{ "minRows": 4, "maxRows": 4 }' maxlength='500'>
                </el-input>
            </el-form-item>
            <el-form-item prop="FileInfo">
                <template v-if="dataForm.FileInfo.length">
                    <ul class="el-upload-list el-upload-list el-upload-list--text">
                        <li class="el-upload-list__item is-success" v-for="(file, index) in dataForm.FileInfo"
                            :key="file.fileId" :class="{ 'el-upload-list__item_detail': true }">
                            <a class="el-upload-list__item-name" @click="handleClick(file)">
                                <i class="el-icon-paperclip"></i>{{ file.name }}
                            </a>
                        </li>
                    </ul>
                </template>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">{{ $t('common.cancelButton') }}</el-button>
            <el-button type="primary" @click="dataFormSubmit()">确 定</el-button>
        </span>
    </el-dialog>
</template>
    
<script>
import { getDownloadUrl } from '@/api/common'
export default {
    data() {
        return {
            visible: false,
            dataForm: {
                DestructivenessQty: "",
                Remarks: "",
                Parameter: [],
                FileInfo: []
            },
            parameter: [],
            readOnly: false,
        }
    },
    methods: {
        init(row, readOnly) {
            this.dataForm = row
            this.readOnly = readOnly

            this.parameter = row.Parameter == "" ? [] : JSON.parse(row.Parameter)
            this.visible = true
        },
        handleClick(file) {
            // 点击下载文件
            if (!file.fileId) return
            getDownloadUrl('annex', file.fileId).then(res => {
                this.shzy.downloadFile(res.data.url)
            })
        },
        dataFormSubmit() {
            this.dataForm.Parameter = JSON.stringify(this.parameter)
            this.visible = false
        }
    }
}
</script>
<style lang="scss" scoped>
.timeline {
    padding-top: 30px;
}

>>>.el-timeline-content {
    p {
        padding: 0;
        margin: 0;
    }

    .text {
        line-height: 20px;
        margin-bottom: 10px;
        color: #475059;
        font-size: 14px;
    }

    .time {
        font-size: 12px;
        display: flex;
        justify-content: space-between;
        opacity: 0.6;

        .del {
            display: none;
            color: rgb(255, 91, 91);
            cursor: pointer;

            i {
                margin-right: 5px;
            }
        }
    }

    &:hover {
        .del {
            display: block;
        }
    }
}
</style>